
/* <<< COPYRIGHT START >>>
 * Copyright 2006-Present OxygenSoftwareLibrary.com
 * Licensed under the GNU Lesser General Public License.
 * http://www.gnu.org/licenses/lgpl.html
 * 
 * @author: Ugorji Dick-Nwoke
 * <<< COPYRIGHT END >>>
 */

package oxygen.tool.wlevs.plugins;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.management.MBeanServerConnection;
import javax.management.remote.JMXConnector;
import javax.management.remote.JMXConnectorServer;

import oxygen.tool.facade.plugins.Connect;
import oxygen.tool.facade.trees.FacadeTreeModel;
import oxygen.tool.wlevs.WLEvSApplicationFacadeTreeModel;
import oxygen.tool.wlevs.WLEvSServicesFacadeTreeModel;

public class WLEvSConnect extends Connect {
  protected Map getJMXConnEnv(String username, String password) throws Exception {
    Map env = new HashMap();
    if(username != null && password != null) {
      env.put(JMXConnector.CREDENTIALS, new String[] {username, password});
    }
    //env.put("jmx.remote.authenticator", "com.bea.core.jmx.server.CEAuthenticator");
    env.put(JMXConnectorServer.AUTHENTICATOR, "com.bea.core.jmx.server.CEAuthenticator");
    return env;
  }
  
  protected void doConnect(String host, int port, MBeanServerConnection mbs, List treesAdded) throws Exception {
    super.doConnect(host, port, mbs, treesAdded);
    FacadeTreeModel ftm = null;
    ftm = new WLEvSApplicationFacadeTreeModel(mbs, "wlevs:application:" + host + ":" + port);
    addTree(ftm, treesAdded);
    ftm = new WLEvSServicesFacadeTreeModel(mbs, "wlevs:services:" + host + ":" + port);
    addTree(ftm, treesAdded);    
  }
    
}

